package com.crungoo;

import com.crungoo.model.A;
import com.crungoo.model.B;
import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.io.support.ResourcePatternResolver;

/**
 * @author fujc-dev@qq.com
 * @description TODO
 * @date 2023/6/22 16:54
 */

public class P2 {

	public static void main(String[] args) {
		//BeanFactory
		//ApplicationContext
		//ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory,
		//MessageSource, ApplicationEventPublisher, ResourcePatternResolver

		// BeanFactory 与 ApplicationContext的关系？
		// 看继承关系，ApplicationContext就是一个BeanFactory（不考虑其他的继承，生硬理解）。

		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
		context.refresh();
		AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		beanDefinition.setBeanClass(A.class);
		context.registerBeanDefinition("a",beanDefinition);
		A a = context.getBean(A.class);
		a.test();

		DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
		AbstractBeanDefinition beanDefinitionB = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		beanDefinitionB.setBeanClass(B.class);
		beanFactory.registerBeanDefinition("b",beanDefinitionB);
		B b = beanFactory.getBean(B.class);
		b.test();
		//  从这个案例可以看出  BeanFactory 与 ApplicationContext好像没有多大的区别。
		//
		//ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory,
		//MessageSource, ApplicationEventPublisher, ResourcePatternResolver
		// ApplicationContext 继承了环境信息、父子BeanFactory国际化等等多样化扩展
	}
}
